package com.fw.ui.view.profile.service.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.vaadin.dialogs.ConfirmDialog;

import com.fw.service.bean.ErrorBean;
import com.fw.service.merchantprofile.bean.MerchantProfileBean;
import com.fw.service.serviceprofile.bean.ServiceProfileBean;
import com.fw.ui.ApplicationUI;
import com.fw.ui.bao.FileBAO;
import com.fw.ui.bao.MerchantProfileBAO;
import com.fw.ui.bao.MessageBAO;
import com.fw.ui.bao.ServiceProfileBAO;
import com.fw.ui.util.SessionInfoUtils;
import com.fw.ui.util.UICommonUtils;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.common.ConfirmDialogWindow;
import com.fw.ui.view.event.AbstractButtonClickListener;
import com.fw.ui.view.profile.CreateCashServiceProfileView;
import com.fw.util.DateUtils;
import com.fw.util.StringUtils;
import com.vaadin.ui.Button.ClickEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class CreateCashServiceProfileSaveButtonClickListener extends AbstractButtonClickListener {

    private static Logger log = Logger.getLogger(CreateCashServiceProfileSaveButtonClickListener.class.getName());
    private static final long serialVersionUID = 1L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;
    @Autowired
    private ServiceProfileBAO serviceProfileBAO;
    @Autowired
    private MerchantProfileBAO merchantProfileBAO;
    @Autowired
    private MessageBAO messageBAO;
    @Autowired
    private UICommonUtils uiCommonUtils;
    @Autowired
    private FileBAO fileBAO;
    @Autowired
    private SessionInfoUtils sessionInfoUtils;

    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> click(ClickEvent event) throws Exception {
	final Map<String, Object> result = new HashMap<String, Object>();
	final CreateCashServiceProfileView createCashServiceProfileView = (CreateCashServiceProfileView) this.getBasedComponent();
	final String serviceId = createCashServiceProfileView.getTxtServiceId().getValue();
	final String merchantId = (String) createCashServiceProfileView.getCbbMerchantId().getValue();
	String merchantNameTH = null;
	if (merchantId != null) {
	    MerchantProfileBean merchantProfileBean = merchantProfileBAO.getMerchantProfileByMerchantId(merchantId);
	    if (merchantProfileBean != null) {
		merchantNameTH = merchantProfileBean.getMerchantNameTh();
	    }
	}
	final String host = (String) createCashServiceProfileView.getCbbHost().getValue();

	String title = messageBAO.getMessage("com.fw.ui.view.profile.CreateCashServiceProfileView.message.confirm.title");
	String okCaption = messageBAO.getMessage("application.button.ok.caption");
	String cancelCaption = messageBAO.getMessage("application.button.cancel.caption");

	String content = messageBAO.getMessageWithParams("com.fw.ui.view.profile.CreateCashServiceProfileView.message.confirm.content",
		new String[] { merchantId, merchantNameTH, serviceId, host });

	ConfirmDialogWindow.createConfirmDialog(createCashServiceProfileView.getUI(), title, content, okCaption, cancelCaption,
		new ConfirmDialog.Listener() {
		    private static final long serialVersionUID = 1L;

		    @Override
		    public void onClose(ConfirmDialog dialog) {
			if (dialog.isConfirmed()) {
			    log.info("Confirm!");
			    Map<String, Serializable> mapResult = null;
			    try {

				Boolean isTestService = createCashServiceProfileView.getCbIsTestService().getValue();
				String serviceStatus = (String) createCashServiceProfileView.getCbbServiceStatus().getValue();
				Boolean isBankGuarantee = createCashServiceProfileView.getCbIsBankGuarantee().getValue();
				String bankGuarantee = createCashServiceProfileView.getTxtBankGuarantee().getValue();
				Date bankGuaranteeExpireDate = createCashServiceProfileView.getPdfBankGuaranteeExpireDate().getValue();
				String bankGuaranteeExpireDateStr = null;
				if (bankGuaranteeExpireDate != null) {
				    bankGuaranteeExpireDateStr = StringUtils.formatDate(bankGuaranteeExpireDate,
					    StringUtils.PATTERN_MONTH_YEAR_PERSISTENCE);
				}
				String chequeName = createCashServiceProfileView.getTxtChequeName().getValue();
				Date launchedDate = createCashServiceProfileView.getPdfLaunchedDate().getValue();
				String launchedDateStr = null;
				if (launchedDate != null) {
				    launchedDateStr = StringUtils.formatDate(launchedDate, StringUtils.PATTERN_DATE_PERSISTENCE);
				}
				Boolean isNotifyCustomer = createCashServiceProfileView.getCbIsNotifyCustomer().getValue();
				Boolean isResponseUrlBack = createCashServiceProfileView.getCbIsResponseUrlBack().getValue();
				String responseUrlBack = createCashServiceProfileView.getTxtResponseUrlBack().getValue();
				Boolean isSuccessUrl = createCashServiceProfileView.getCbIsSuccessUrl().getValue();
				String successUrl = createCashServiceProfileView.getTxtSuccessUrl().getValue();
				Boolean isFailUrl = createCashServiceProfileView.getCbIsFailUrl().getValue();
				String failUrl = createCashServiceProfileView.getTxtFailUrl().getValue();
				Boolean isCancelUrl = createCashServiceProfileView.getCbIsCancelUrl().getValue();
				String cancelUrl = createCashServiceProfileView.getTxtCancelUrl().getValue();

				String invoiceAging = createCashServiceProfileView.getTxtInvoiceAging().getValue();
				Boolean isBypassInvoiceAging = createCashServiceProfileView.getCbIsBypassInvoiceAging().getValue();
				String bankCodeAndName = (String) createCashServiceProfileView.getCbbBankCodeAndName().getValue();
				String bankAccountNo = createCashServiceProfileView.getTxtBankAccountNo().getValue();
				String sapArCode = createCashServiceProfileView.getTxtSapArCode().getValue();
				String sapApCode = createCashServiceProfileView.getTxtSapApCode().getValue();
				String messageSlip1 = createCashServiceProfileView.getTxtMessageSlip1().getValue();
				String messageSlip2 = createCashServiceProfileView.getTxtMessageSlip2().getValue();
				String mdr = createCashServiceProfileView.getTxtMdr().getValue();
				String serviceFee = createCashServiceProfileView.getTxtServiceFee().getValue();

				String dailyLimit = createCashServiceProfileView.getTxtDailyLimit().getValue();
				String monthlyLimit = createCashServiceProfileView.getTxtMonthlyLimit().getValue();
				String transactionAmountLimit = createCashServiceProfileView.getTxtTransactionAmountLimit().getValue();

				String contact1Name = createCashServiceProfileView.getTxtProjectContactName().getValue();
				String contact1Mobile = createCashServiceProfileView.getTxtProjectContactMobile().getValue();
				String contact1Email = createCashServiceProfileView.getTxtProjectContactEmailAddress().getValue();
				String contact1Phone = createCashServiceProfileView.getTxtProjectContactPhone().getValue();

				String contact2Name = createCashServiceProfileView.getTxtOperationContactName().getValue();
				String contact2Mobile = createCashServiceProfileView.getTxtOperationContactMobile().getValue();
				String contact2Email = createCashServiceProfileView.getTxtOperationContactEmailAddress().getValue();
				String contact2Phone = createCashServiceProfileView.getTxtOperationContactPhone().getValue();

				String contact3Name = createCashServiceProfileView.getTxtTechnicalContactName().getValue();
				String contact3Mobile = createCashServiceProfileView.getTxtTechnicalContactMobile().getValue();
				String contact3Email = createCashServiceProfileView.getTxtTechnicalContactEmailAddress().getValue();
				String contact3Phone = createCashServiceProfileView.getTxtTechnicalContactPhone().getValue();

				String contact4Name = createCashServiceProfileView.getTxtFinancialContactName().getValue();
				String contact4Mobile = createCashServiceProfileView.getTxtFinancialContactMobile().getValue();
				String contact4Email = createCashServiceProfileView.getTxtFinancialContactEmailAddress().getValue();
				String contact4Phone = createCashServiceProfileView.getTxtFinancialContactPhone().getValue();

				ServiceProfileBean serviceProfileBean = new ServiceProfileBean();
				serviceProfileBean.setServiceId(serviceId);
				serviceProfileBean.setMerchantId(merchantId);
				serviceProfileBean.setServiceStatus(serviceStatus);
				serviceProfileBean.setHost(host);
				serviceProfileBean.setIsBankGuarantee(isBankGuarantee);
				serviceProfileBean.setBankGuarantee(bankGuarantee);
				serviceProfileBean.setBankGuaranteeExpireDate(bankGuaranteeExpireDateStr);
				serviceProfileBean.setChequeName(chequeName);
				serviceProfileBean.setLaunchedDate(launchedDateStr);
				serviceProfileBean.setIsResponseUrlBack(isResponseUrlBack);
				serviceProfileBean.setResponseUrlBack(responseUrlBack);
				serviceProfileBean.setIsSuccessUrl(isSuccessUrl);
				serviceProfileBean.setSuccessUrl(successUrl);
				serviceProfileBean.setIsFailUrl(isFailUrl);
				serviceProfileBean.setFailUrl(failUrl);
				serviceProfileBean.setIsCancelUrl(isCancelUrl);
				serviceProfileBean.setCancelUrl(cancelUrl);
				serviceProfileBean.setIsNotifyCustomer(isNotifyCustomer);
				serviceProfileBean.setIsTestService(isTestService);
				serviceProfileBean.setInvoiceAging(invoiceAging);
				serviceProfileBean.setIsBypassInvoiceAging(isBypassInvoiceAging);
				serviceProfileBean.setBankCodeAndName(bankCodeAndName);
				serviceProfileBean.setBankAccountNo(bankAccountNo);
				serviceProfileBean.setSapArCode(sapArCode);
				serviceProfileBean.setSapApCode(sapApCode);
				serviceProfileBean.setMessageSlip1(messageSlip1);
				serviceProfileBean.setMessageSlip2(messageSlip2);
				serviceProfileBean.setMdr(mdr);
				serviceProfileBean.setServiceFee(serviceFee);
				serviceProfileBean.setDailyLimit(dailyLimit);
				serviceProfileBean.setMonthlyLimit(monthlyLimit);
				serviceProfileBean.setTransactionAmountLimit(transactionAmountLimit);

				serviceProfileBean.setContact1Name(contact1Name);
				serviceProfileBean.setContact1Mobile(contact1Mobile);
				serviceProfileBean.setContact1Email(contact1Email);
				serviceProfileBean.setContact1Phone(contact1Phone);

				serviceProfileBean.setContact2Name(contact2Name);
				serviceProfileBean.setContact2Mobile(contact2Mobile);
				serviceProfileBean.setContact2Email(contact2Email);
				serviceProfileBean.setContact2Phone(contact2Phone);

				serviceProfileBean.setContact3Name(contact3Name);
				serviceProfileBean.setContact3Mobile(contact3Mobile);
				serviceProfileBean.setContact3Email(contact3Email);
				serviceProfileBean.setContact3Phone(contact3Phone);

				serviceProfileBean.setContact4Name(contact4Name);
				serviceProfileBean.setContact4Mobile(contact4Mobile);
				serviceProfileBean.setContact4Email(contact4Email);
				serviceProfileBean.setContact4Phone(contact4Phone);

				ApplicationUI applicationUI = (ApplicationUI) createCashServiceProfileView.getUI();
				sessionInfoUtils.setSessionInfoDetails(serviceProfileBean, applicationUI.getAuthenticationBean(),
					applicationUI.getLocale());

				mapResult = serviceProfileBAO.createServiceProfile(serviceProfileBean);

				if (mapResult != null) {
				    List<ErrorBean> errorBeans = (List<ErrorBean>) mapResult.get(List.class.getName() + "."
					    + ErrorBean.class.getName());
				    serviceProfileBean = (ServiceProfileBean) mapResult.get(ServiceProfileBean.class.getName());
				    if (errorBeans != null && !errorBeans.isEmpty()) {
					result.put(MessageBAO.MESSAGE_WARNING_TYPE, errorBeans);
				    } else {
					if (serviceProfileBean != null && serviceProfileBean.getId() != null) {
					    uiCommonUtils.clearAllUIComponentWithPrefixDefaultValue(createCashServiceProfileView, null);

					    // default data
					    createCashServiceProfileView.getPdfLaunchedDate().setValue(DateUtils.getCurrentDate());
					    createCashServiceProfileView.getTxtMdr().setValue("0");
					    createCashServiceProfileView.getTxtServiceFee().setValue("0");
					    createCashServiceProfileView.getTxtInvoiceAging().setValue("2");
					    createCashServiceProfileView.getTxtDailyLimit().setValue("-1");
					    createCashServiceProfileView.getTxtMonthlyLimit().setValue("-1");
					    createCashServiceProfileView.getTxtTransactionAmountLimit().setValue("30001");

					    result.put(MessageBAO.MESSAGE_INFO_TYPE,
						    "com.fw.ui.view.profile.CreateCashServiceProfileView.message.created");
					} else {
					    result.put(MessageBAO.MESSAGE_WARNING_TYPE,
						    "com.fw.ui.view.profile.CreateCashServiceProfileView.message.failed");
					}
				    }
				} else {
				    result.put(MessageBAO.MESSAGE_WARNING_TYPE, "message.error.common");
				}
			    } catch (Exception e) {
				result.put(MessageBAO.MESSAGE_WARNING_TYPE, "message.error.common");
			    }
			    // notification
			    notification(result);
			} else {
			    log.info("Cancel Confirm!");
			}
		    }
		}, "220px", "500px");

	return null;
    }

    @Override
    public boolean validate(ClickEvent event) {
	boolean validate = false;
	CreateCashServiceProfileView createCashServiceProfileView = (CreateCashServiceProfileView) this.getBasedComponent();
	try {

	    uiCommonUtils.clearAllUIComponentNoInputFieldWithPrefix(createCashServiceProfileView);

	    boolean isTestServiceValid = createCashServiceProfileView.getCbIsTestService().isValid();
	    boolean serviceIdValid = createCashServiceProfileView.getTxtServiceId().isValid();
	    boolean merchantIdValid = createCashServiceProfileView.getCbbMerchantId().isValid();
	    boolean serviceStatusValid = createCashServiceProfileView.getCbbServiceStatus().isValid();
	    boolean hostValid = createCashServiceProfileView.getCbbHost().isValid();
	    boolean bankGuaranteeValid = createCashServiceProfileView.getTxtBankGuarantee().isValid();
	    boolean bankGuaranteeExpireDateValid = createCashServiceProfileView.getPdfBankGuaranteeExpireDate().isValid();
	    boolean chequeNameValid = createCashServiceProfileView.getTxtChequeName().isValid();
	    boolean launchedDateValid = createCashServiceProfileView.getPdfLaunchedDate().isValid();
	    boolean isNotifyCustomerValid = createCashServiceProfileView.getCbIsNotifyCustomer().isValid();
	    boolean responseUrlBackValid = createCashServiceProfileView.getTxtResponseUrlBack().isValid();
	    boolean successUrlValid = createCashServiceProfileView.getTxtSuccessUrl().isValid();
	    boolean faileUrlValid = createCashServiceProfileView.getTxtFailUrl().isValid();
	    boolean cancelUrlValid = createCashServiceProfileView.getTxtCancelUrl().isValid();

	    boolean invoiceAgingValid = createCashServiceProfileView.getTxtInvoiceAging().isValid();
	    boolean isBypassInvoiceAgingValid = createCashServiceProfileView.getCbIsBypassInvoiceAging().isValid();
	    boolean bankCodeAndNameValid = createCashServiceProfileView.getCbbBankCodeAndName().isValid();
	    boolean bankAccountNoValid = createCashServiceProfileView.getTxtBankAccountNo().isValid();
	    boolean sapArCodeValid = createCashServiceProfileView.getTxtSapArCode().isValid();
	    boolean sapApCodeValid = createCashServiceProfileView.getTxtSapApCode().isValid();
	    boolean messageSlip1Valid = createCashServiceProfileView.getTxtMessageSlip1().isValid();
	    boolean messageSlip2Valid = createCashServiceProfileView.getTxtMessageSlip2().isValid();
	    boolean mdrValid = createCashServiceProfileView.getTxtMdr().isValid();
	    boolean serviceFeeValid = createCashServiceProfileView.getTxtServiceFee().isValid();

	    boolean dailyLimitValid = createCashServiceProfileView.getTxtDailyLimit().isValid();
	    boolean monthlyLimitValid = createCashServiceProfileView.getTxtMonthlyLimit().isValid();
	    boolean transactionAmountLimitValid = createCashServiceProfileView.getTxtTransactionAmountLimit().isValid();

	    boolean projectContactNameValid = createCashServiceProfileView.getTxtProjectContactName().isValid();
	    boolean projectContactPhoneValid = createCashServiceProfileView.getTxtProjectContactPhone().isValid();
	    boolean projectContactMobileValid = createCashServiceProfileView.getTxtProjectContactMobile().isValid();
	    boolean projectContactEmailAddressValid = createCashServiceProfileView.getTxtProjectContactEmailAddress().isValid();
	    boolean technicalContactNameValid = createCashServiceProfileView.getTxtTechnicalContactName().isValid();
	    boolean technicalContactPhoneValid = createCashServiceProfileView.getTxtTechnicalContactPhone().isValid();
	    boolean technicalContactMobileValid = createCashServiceProfileView.getTxtTechnicalContactMobile().isValid();
	    boolean technicalContactEmailAddressValid = createCashServiceProfileView.getTxtTechnicalContactEmailAddress().isValid();
	    boolean operationContactNameValid = createCashServiceProfileView.getTxtOperationContactName().isValid();
	    boolean operationContactPhoneValid = createCashServiceProfileView.getTxtOperationContactPhone().isValid();
	    boolean operationContactMobileValid = createCashServiceProfileView.getTxtOperationContactMobile().isValid();
	    boolean operationContactEmailAddressValid = createCashServiceProfileView.getTxtOperationContactEmailAddress().isValid();
	    boolean financialContactNameValid = createCashServiceProfileView.getTxtFinancialContactName().isValid();
	    boolean financialContactPhoneValid = createCashServiceProfileView.getTxtFinancialContactPhone().isValid();
	    boolean financialContactMobileValid = createCashServiceProfileView.getTxtFinancialContactMobile().isValid();
	    boolean financialContactEmailAddressValid = createCashServiceProfileView.getTxtFinancialContactEmailAddress().isValid();

	    if (isTestServiceValid && serviceIdValid && merchantIdValid && serviceStatusValid && hostValid && bankGuaranteeValid
		    && bankGuaranteeExpireDateValid && chequeNameValid && launchedDateValid && isNotifyCustomerValid
		    && responseUrlBackValid && successUrlValid && faileUrlValid && cancelUrlValid && invoiceAgingValid
		    && isBypassInvoiceAgingValid && bankCodeAndNameValid && bankAccountNoValid && sapArCodeValid && sapApCodeValid
		    && messageSlip1Valid && messageSlip2Valid && mdrValid && serviceFeeValid && dailyLimitValid && monthlyLimitValid
		    && transactionAmountLimitValid && projectContactNameValid && projectContactPhoneValid && projectContactMobileValid
		    && projectContactEmailAddressValid && technicalContactNameValid && technicalContactPhoneValid
		    && technicalContactMobileValid && technicalContactEmailAddressValid && operationContactNameValid
		    && operationContactPhoneValid && operationContactMobileValid && operationContactEmailAddressValid
		    && financialContactNameValid && financialContactPhoneValid && financialContactMobileValid
		    && financialContactEmailAddressValid) {

		Boolean isUnique = this.serviceProfileBAO.checkUniqueServiceId(createCashServiceProfileView.getTxtServiceId().getValue());
		if (isUnique == null || !isUnique.booleanValue()) {
		    createCashServiceProfileView.getTxtServiceId().addStyleName("v-textfield-error");
		    createCashServiceProfileView.getLblServiceIdValidateMessage().setValue(
			    this.messageBAO.getMessage("com.fw.ui.view.profile.CreateCashServiceProfileView.message.serviceId.exist"));
		    createCashServiceProfileView.getLayoutServiceIdValidate().setVisible(true);
		} else {
		    validate = true;
		}
	    } else {
		if (!isTestServiceValid) {
		    createCashServiceProfileView.getCbIsTestService().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getCbIsTestService().getErrorMessage() != null) {
			createCashServiceProfileView.getLblIsTestServiceValidateMessage().setValue(
				createCashServiceProfileView.getCbIsTestService().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutIsTestServiceValidate().setVisible(true);
		}
		if (!serviceIdValid) {
		    createCashServiceProfileView.getTxtServiceId().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtServiceId().getErrorMessage() != null) {
			createCashServiceProfileView.getLblServiceIdValidateMessage().setValue(
				createCashServiceProfileView.getTxtServiceId().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutServiceIdValidate().setVisible(true);
		} else {
		    Boolean isUnique = this.serviceProfileBAO.checkUniqueServiceId(createCashServiceProfileView.getTxtServiceId()
			    .getValue());
		    if (isUnique == null || !isUnique.booleanValue()) {
			createCashServiceProfileView.getTxtServiceId().addStyleName("v-textfield-error");
			createCashServiceProfileView.getLblServiceIdValidateMessage().setValue(
				this.messageBAO.getMessage("com.fw.ui.view.profile.CreateCashServiceProfileView.message.serviceId.exist"));
			createCashServiceProfileView.getLayoutServiceIdValidate().setVisible(true);
		    }
		}
		if (!merchantIdValid) {
		    createCashServiceProfileView.getCbbMerchantId().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getCbbMerchantId().getErrorMessage() != null) {
			createCashServiceProfileView.getLblMerchantIdValidateMessage().setValue(
				createCashServiceProfileView.getCbbMerchantId().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutMerchantIdValidate().setVisible(true);
		}
		if (!serviceStatusValid) {
		    createCashServiceProfileView.getCbbServiceStatus().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getCbbServiceStatus().getErrorMessage() != null) {
			createCashServiceProfileView.getLblServiceStatusValidateMessage().setValue(
				createCashServiceProfileView.getCbbServiceStatus().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutServiceStatusValidate().setVisible(true);
		}
		if (!hostValid) {
		    createCashServiceProfileView.getCbbHost().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getCbbHost().getErrorMessage() != null) {
			createCashServiceProfileView.getLblHostValidateMessage().setValue(
				createCashServiceProfileView.getCbbHost().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutHostValidate().setVisible(true);
		}
		if (!bankGuaranteeValid) {
		    createCashServiceProfileView.getTxtBankGuarantee().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtBankGuarantee().getErrorMessage() != null) {
			createCashServiceProfileView.getLblBankGuaranteeValidateMessage().setValue(
				createCashServiceProfileView.getTxtBankGuarantee().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutBankGuaranteeValidate().setVisible(true);
		}

		if (!bankGuaranteeExpireDateValid) {
		    createCashServiceProfileView.getPdfBankGuaranteeExpireDate().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getPdfBankGuaranteeExpireDate().getErrorMessage() != null) {
			createCashServiceProfileView.getLblBankGuaranteeExpireDateValidateMessage().setValue(
				createCashServiceProfileView.getPdfBankGuaranteeExpireDate().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutBankGuaranteeExpireDateValidate().setVisible(true);
		}
		if (!chequeNameValid) {
		    createCashServiceProfileView.getTxtChequeName().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtChequeName().getErrorMessage() != null) {
			createCashServiceProfileView.getLblChequeNameValidateMessage().setValue(
				createCashServiceProfileView.getTxtChequeName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutChequeNameValidate().setVisible(true);
		}
		if (!launchedDateValid) {
		    createCashServiceProfileView.getPdfLaunchedDate().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getPdfLaunchedDate().getErrorMessage() != null) {
			createCashServiceProfileView.getLblLaunchedDateValidateMessage().setValue(
				createCashServiceProfileView.getPdfLaunchedDate().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutLaunchedDateValidate().setVisible(true);
		}
		if (!isNotifyCustomerValid) {
		    createCashServiceProfileView.getCbIsNotifyCustomer().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getCbIsNotifyCustomer().getErrorMessage() != null) {
			createCashServiceProfileView.getLblNotifyCustomerValidateMessage().setValue(
				createCashServiceProfileView.getCbIsNotifyCustomer().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutNotifyCustomerValidate().setVisible(true);
		}
		if (!responseUrlBackValid) {
		    createCashServiceProfileView.getTxtResponseUrlBack().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtResponseUrlBack().getErrorMessage() != null) {
			createCashServiceProfileView.getLblResponseUrlBackValidateMessage().setValue(
				createCashServiceProfileView.getTxtResponseUrlBack().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutResponseUrlBackValidate().setVisible(true);
		}

		if (!successUrlValid) {
		    createCashServiceProfileView.getTxtSuccessUrl().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtSuccessUrl().getErrorMessage() != null) {
			createCashServiceProfileView.getLblSuccessUrlValidateMessage().setValue(
				createCashServiceProfileView.getTxtSuccessUrl().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutSuccessUrlValidate().setVisible(true);
		}

		if (!faileUrlValid) {
		    createCashServiceProfileView.getTxtFailUrl().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtFailUrl().getErrorMessage() != null) {
			createCashServiceProfileView.getLblFailUrlValidateMessage().setValue(
				createCashServiceProfileView.getTxtFailUrl().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutFailUrlValidate().setVisible(true);
		}

		if (!cancelUrlValid) {
		    createCashServiceProfileView.getTxtCancelUrl().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtCancelUrl().getErrorMessage() != null) {
			createCashServiceProfileView.getLblCancelUrlValidateMessage().setValue(
				createCashServiceProfileView.getTxtCancelUrl().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutCancelUrlValidate().setVisible(true);
		}

		if (!invoiceAgingValid) {
		    createCashServiceProfileView.getTxtInvoiceAging().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtInvoiceAging().getErrorMessage() != null) {
			createCashServiceProfileView.getLblInvoiceAgingValidateMessage().setValue(
				createCashServiceProfileView.getTxtInvoiceAging().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutInvoiceAgingValidate().setVisible(true);
		}
		if (!isBypassInvoiceAgingValid) {
		    createCashServiceProfileView.getCbIsBypassInvoiceAging().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getCbIsBypassInvoiceAging().getErrorMessage() != null) {
			createCashServiceProfileView.getLblBypassInvoiceAgingValidateMessage().setValue(
				createCashServiceProfileView.getCbIsBypassInvoiceAging().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutBypassInvoiceAgingValidate().setVisible(true);
		}
		if (!bankCodeAndNameValid) {
		    createCashServiceProfileView.getCbbBankCodeAndName().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getCbbBankCodeAndName().getErrorMessage() != null) {
			createCashServiceProfileView.getLblBankCodeAndNameValidateMessage().setValue(
				createCashServiceProfileView.getCbbBankCodeAndName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutBankCodeAndNameValidate().setVisible(true);
		}
		if (!bankAccountNoValid) {
		    createCashServiceProfileView.getTxtBankAccountNo().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtBankAccountNo().getErrorMessage() != null) {
			createCashServiceProfileView.getLblBankAccountNoValidateMessage().setValue(
				createCashServiceProfileView.getTxtBankAccountNo().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutBankAccountNoValidate().setVisible(true);
		}
		if (!sapArCodeValid) {
		    createCashServiceProfileView.getTxtSapArCode().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtSapArCode().getErrorMessage() != null) {
			createCashServiceProfileView.getLblSapArCodeValidateMessage().setValue(
				createCashServiceProfileView.getTxtSapArCode().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutSapArCodeValidate().setVisible(true);
		}
		if (!sapApCodeValid) {
		    createCashServiceProfileView.getTxtSapApCode().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtSapApCode().getErrorMessage() != null) {
			createCashServiceProfileView.getLblSapApCodeValidateMessage().setValue(
				createCashServiceProfileView.getTxtSapApCode().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutSapApCodeValidate().setVisible(true);
		}
		if (!messageSlip1Valid) {
		    createCashServiceProfileView.getTxtMessageSlip1().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtMessageSlip1().getErrorMessage() != null) {
			createCashServiceProfileView.getLblMessageSlip1ValidateMessage().setValue(
				createCashServiceProfileView.getTxtMessageSlip1().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutMessageSlip1Validate().setVisible(true);
		}
		if (!messageSlip2Valid) {
		    createCashServiceProfileView.getTxtMessageSlip2().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtMessageSlip2().getErrorMessage() != null) {
			createCashServiceProfileView.getLblMessageSlip2ValidateMessage().setValue(
				createCashServiceProfileView.getTxtMessageSlip2().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutMessageSlip2Validate().setVisible(true);
		}
		if (!mdrValid) {
		    createCashServiceProfileView.getTxtMdr().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtMdr().getErrorMessage() != null) {
			createCashServiceProfileView.getLblMdrValidateMessage().setValue(
				createCashServiceProfileView.getTxtMdr().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutMdrValidate().setVisible(true);
		}
		if (!serviceFeeValid) {
		    createCashServiceProfileView.getTxtServiceFee().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtServiceFee().getErrorMessage() != null) {
			createCashServiceProfileView.getLblServiceFeeValidateMessage().setValue(
				createCashServiceProfileView.getTxtServiceFee().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutServiceFeeValidate().setVisible(true);
		}

		if (!dailyLimitValid) {
		    createCashServiceProfileView.getTxtDailyLimit().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtDailyLimit().getErrorMessage() != null) {
			createCashServiceProfileView.getLblDailyLimitValidateMessage().setValue(
				createCashServiceProfileView.getTxtDailyLimit().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutDailyLimitValidate().setVisible(true);
		}
		if (!monthlyLimitValid) {
		    createCashServiceProfileView.getTxtMonthlyLimit().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtMonthlyLimit().getErrorMessage() != null) {
			createCashServiceProfileView.getLblMonthlyLimitValidateMessage().setValue(
				createCashServiceProfileView.getTxtMonthlyLimit().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutMonthlyLimitValidate().setVisible(true);
		}
		if (!transactionAmountLimitValid) {
		    createCashServiceProfileView.getTxtTransactionAmountLimit().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtTransactionAmountLimit().getErrorMessage() != null) {
			createCashServiceProfileView.getLblTransactionAmountLimitValidateMessage().setValue(
				createCashServiceProfileView.getTxtTransactionAmountLimit().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutTransactionAmountLimitValidate().setVisible(true);
		}

		// project
		if (!projectContactNameValid) {
		    createCashServiceProfileView.getTxtProjectContactName().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtProjectContactName().getErrorMessage() != null) {
			createCashServiceProfileView.getLblProjectContactNameValidateMessage().setValue(
				createCashServiceProfileView.getTxtProjectContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutProjectContactNameValidate().setVisible(true);
		}
		if (!projectContactPhoneValid) {
		    createCashServiceProfileView.getTxtProjectContactPhone().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtProjectContactPhone().getErrorMessage() != null) {
			createCashServiceProfileView.getLblProjectContactPhoneValidateMessage().setValue(
				createCashServiceProfileView.getTxtProjectContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutProjectContactPhoneValidate().setVisible(true);
		}
		if (!projectContactMobileValid) {
		    createCashServiceProfileView.getTxtProjectContactMobile().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtProjectContactMobile().getErrorMessage() != null) {
			createCashServiceProfileView.getLblProjectContactMobileValidateMessage().setValue(
				createCashServiceProfileView.getTxtProjectContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutProjectContactMobileValidate().setVisible(true);
		}
		if (!projectContactEmailAddressValid) {
		    createCashServiceProfileView.getTxtProjectContactEmailAddress().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtProjectContactEmailAddress().getErrorMessage() != null) {
			createCashServiceProfileView.getLblProjectContactEmailAddressValidateMessage()
				.setValue(
					createCashServiceProfileView.getTxtProjectContactEmailAddress().getErrorMessage()
						.getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutProjectContactEmailAddressValidate().setVisible(true);
		}
		// operation
		if (!operationContactNameValid) {
		    createCashServiceProfileView.getTxtOperationContactName().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtOperationContactName().getErrorMessage() != null) {
			createCashServiceProfileView.getLblOperationContactNameValidateMessage().setValue(
				createCashServiceProfileView.getTxtOperationContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutOperationContactNameValidate().setVisible(true);
		}
		if (!operationContactPhoneValid) {
		    createCashServiceProfileView.getTxtOperationContactPhone().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtOperationContactPhone().getErrorMessage() != null) {
			createCashServiceProfileView.getLblOperationContactPhoneValidateMessage().setValue(
				createCashServiceProfileView.getTxtOperationContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutOperationContactPhoneValidate().setVisible(true);
		}
		if (!operationContactMobileValid) {
		    createCashServiceProfileView.getTxtOperationContactMobile().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtOperationContactMobile().getErrorMessage() != null) {
			createCashServiceProfileView.getLblOperationContactMobileValidateMessage().setValue(
				createCashServiceProfileView.getTxtOperationContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutOperationContactMobileValidate().setVisible(true);
		}
		if (!operationContactEmailAddressValid) {
		    createCashServiceProfileView.getTxtOperationContactEmailAddress().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtOperationContactEmailAddress().getErrorMessage() != null) {
			createCashServiceProfileView.getLblOperationContactEmailAddressValidateMessage().setValue(
				createCashServiceProfileView.getTxtOperationContactEmailAddress().getErrorMessage()
					.getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutOperationContactEmailAddressValidate().setVisible(true);
		}
		// technical
		if (!technicalContactNameValid) {
		    createCashServiceProfileView.getTxtTechnicalContactName().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtTechnicalContactName().getErrorMessage() != null) {
			createCashServiceProfileView.getLblTechnicalContactNameValidateMessage().setValue(
				createCashServiceProfileView.getTxtTechnicalContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutTechnicalContactNameValidate().setVisible(true);
		}
		if (!technicalContactPhoneValid) {
		    createCashServiceProfileView.getTxtTechnicalContactPhone().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtTechnicalContactPhone().getErrorMessage() != null) {
			createCashServiceProfileView.getLblTechnicalContactPhoneValidateMessage().setValue(
				createCashServiceProfileView.getTxtTechnicalContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutTechnicalContactPhoneValidate().setVisible(true);
		}
		if (!technicalContactMobileValid) {
		    createCashServiceProfileView.getTxtTechnicalContactMobile().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtTechnicalContactMobile().getErrorMessage() != null) {
			createCashServiceProfileView.getLblTechnicalContactMobileValidateMessage().setValue(
				createCashServiceProfileView.getTxtTechnicalContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutTechnicalContactMobileValidate().setVisible(true);
		}
		if (!technicalContactEmailAddressValid) {
		    createCashServiceProfileView.getTxtTechnicalContactEmailAddress().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtTechnicalContactEmailAddress().getErrorMessage() != null) {
			createCashServiceProfileView.getLblTechnicalContactEmailAddressValidateMessage().setValue(
				createCashServiceProfileView.getTxtTechnicalContactEmailAddress().getErrorMessage()
					.getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutTechnicalContactEmailAddressValidate().setVisible(true);
		}
		// financial
		if (!financialContactNameValid) {
		    createCashServiceProfileView.getTxtFinancialContactName().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtFinancialContactName().getErrorMessage() != null) {
			createCashServiceProfileView.getLblFinancialContactNameValidateMessage().setValue(
				createCashServiceProfileView.getTxtFinancialContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutFinancialContactNameValidate().setVisible(true);
		}
		if (!financialContactPhoneValid) {
		    createCashServiceProfileView.getTxtFinancialContactPhone().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtFinancialContactPhone().getErrorMessage() != null) {
			createCashServiceProfileView.getLblFinancialContactPhoneValidateMessage().setValue(
				createCashServiceProfileView.getTxtFinancialContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutFinancialContactPhoneValidate().setVisible(true);
		}
		if (!financialContactMobileValid) {
		    createCashServiceProfileView.getTxtFinancialContactMobile().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtFinancialContactMobile().getErrorMessage() != null) {
			createCashServiceProfileView.getLblFinancialContactMobileValidateMessage().setValue(
				createCashServiceProfileView.getTxtFinancialContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutFinancialContactMobileValidate().setVisible(true);
		}
		if (!financialContactEmailAddressValid) {
		    createCashServiceProfileView.getTxtFinancialContactEmailAddress().addStyleName("v-textfield-error");
		    if (createCashServiceProfileView.getTxtFinancialContactEmailAddress().getErrorMessage() != null) {
			createCashServiceProfileView.getLblFinancialContactEmailAddressValidateMessage().setValue(
				createCashServiceProfileView.getTxtFinancialContactEmailAddress().getErrorMessage()
					.getFormattedHtmlMessage());
		    }
		    createCashServiceProfileView.getLayoutFinancialContactEmailAddressValidate().setVisible(true);
		}

	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return validate;
    }
}
